<?php
// +----------------------------------------------------------------------
// | 志进科技
// +----------------------------------------------------------------------
// | 官方网站: http://www.zhijin101.com
// +----------------------------------------------------------------------
// | Author: 张亚伟 <1743325520@qq.com>
// +----------------------------------------------------------------------

namespace Api\Controller;
/**
 * 物流
 */
class LogisticsController extends ApiController
{
    protected $noCheck = ['info'];

    function _initialize() {
        parent::_initialize();
    }

    public function info()
    {
        $order_id = I('order_id');
        $order = M('order')->where(['id'=>$order_id])->find();
        if(empty($order)){
            $this->ajaxReturn(['s'=>false, 'msg'=>'订单不存在']);
        }
        $img = '';
        $order_info = M('order_info')->where(['code'=>$order['code']])->find();
        if($order_info){
            $product = M('product')->where(['id'=>$order_info['pid']])->find();
            if($product){
                if($product['listimg']){
                    $product['listimg'] = json_decode($product['listimg'], true);
                    $img = $product['listimg'][0];
                }
            }
        }
        if(!$order['logistics_type'] || !$order['logistics_code']){
            $this->ajaxReturn(['s'=>false, 'msg'=>'订单还未发货']);
        }
        $logistics = logistics_com($order['logistics_type']);
        if($logistics){
            $logistics['logistics_name'] = $order['logistics_type'];
            $logistics['logistics_code'] = $order['logistics_code'];
            $result = queryExpress($logistics['com'], $order['logistics_code']);
            $this->ajaxReturn(['s'=>true, 'msg'=>'ok', 'img'=>$img ,'logistics'=>$logistics, 'result'=>$result]);
        }else{
            $this->ajaxReturn(['s'=>false, 'msg'=>'该物流还未接入', 'img'=>$img ,'logistics'=>$logistics]);
        }
    }
}